const { Article } = require('../../model/article')


module.exports = async (req, res) => {
  //    标识当前访问为文章管理页面
  req.app.locals.currentLink = 'article';

 // 获取ID参数，判断新增还是修改
 const { message, id } = req.query;
  
 if (id) {
    // 修改操作
    let article = await Article.findOne({ _id: id });
    res.render('admin/article-edit', {
      //  渲染用户编辑页面
      message: message,
      article: article,
      link: '/admin/article-modify?id=' + id,
      button: '修改'
    });
  } else {
    // 添加操作
    res.render('admin/article-edit', {
      message: message,
      article: article,
      link: '/admin/article-add?id=' + id,
      button: '添加'
    });
  }



}